import {Attorney} from "../../models/attorney";
import {config} from "../../config/config";
import {showToast} from "../../util/ui";

Page({
  data: {
    swiperArr: [
      {
        url: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.pinda.net.cn%2Fpic%2Fallimg%2Fcopyright%2Fimg%2Fb7a8c2c91_2.jpg&refer=http%3A%2F%2Fwww.pinda.net.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1648281343&t=26bc604782069ab37e39b20020e5f214',
        id: '001'
      }, {
        url: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimagepphcloud.thepaper.cn%2Fpph%2Fimage%2F67%2F86%2F63.jpg&refer=http%3A%2F%2Fimagepphcloud.thepaper.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1648281343&t=43729fbf9a8bdbad03582af36d3cd590',
        id: '002'
      }, {
        url: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fp1.itc.cn%2Fq_70%2Fimages03%2F20211209%2F475f0bc290774782aa24bb65bf3b49c2.png&refer=http%3A%2F%2Fp1.itc.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1648281343&t=813c2d2ca48e16f903702dbbdef94c77',
        id: '003'
      }, {
        url: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.npazone.com%2FUploads%2Fnews%2F2020-01-16%2F1579165297586998.jpg&refer=http%3A%2F%2Fwww.npazone.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1648281443&t=55920c3c362a5a81f4faa8a8f7512a6f',
        id: '004'
      }],
    list: [],
    queryParams: {
      pageNum: 1,
      pageSize: 10
    },
    showLoading: true,
    listTotal: 0,
    lock: false
  },
  async onLoad(options) {
    await this.getAttorneyList()
  },
  async getAttorneyList() {
    this.setData({
      showLoading: true,
      lock: true
    })
    const res = await Attorney.doApiGetListAttorney(this.data.queryParams)
    res.rows.forEach(item => {
      item.profilephoto = config.apiBaseUrl + item.profilephoto
    })
    this.setData({
      list: this.data.list.concat(res.rows),
      listTotal: res.total,
      showLoading: false,
      lock: false
    })
  },
  onEliteItem(e) {
    const id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `../elite-detail/elite-detail?id=${id}`
    })

  },
  async onReachBottom() {
    const listLength = this.data.list.length
    if (this.data.listTotal <= listLength) {
      showToast('没有更多数据了')
      return
    }
    this.setData({
      "queryParams.pageNum": this.data.queryParams.pageNum++
    })
    if (this.data.lock) return
    await this.getAttorneyList()
  }
})
